package com.ruoyi.project.system.orderteamuser.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.orderteamuser.domain.OrderTeamUser;
import com.ruoyi.project.system.orderteamuser.service.IOrderTeamUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 拼团订单人员Controller
 * 
 * @author f_baisi
 * @date 2021-03-04
 */
@Controller
@RequestMapping("/system/orderteamuser")
public class OrderTeamUserController extends BaseController
{
    private String prefix = "system/orderteamuser";

    @Autowired
    private IOrderTeamUserService orderTeamUserService;

    @RequiresPermissions("system:orderteamuser:view")
    @GetMapping()
    public String orderteamuser()
    {
        return prefix + "/orderteamuser";
    }

    /**
     * 查询拼团订单人员列表
     */
    @RequiresPermissions("system:orderteamuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderTeamUser orderTeamUser)
    {
        startPage();
        List<OrderTeamUser> list = orderTeamUserService.selectOrderTeamUserList(orderTeamUser);
        return getDataTable(list);
    }

    /**
     * 导出拼团订单人员列表
     */
    @RequiresPermissions("system:orderteamuser:export")
    @Log(title = "拼团订单人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderTeamUser orderTeamUser)
    {
        List<OrderTeamUser> list = orderTeamUserService.selectOrderTeamUserList(orderTeamUser);
        ExcelUtil<OrderTeamUser> util = new ExcelUtil<OrderTeamUser>(OrderTeamUser.class);
        return util.exportExcel(list, "orderteamuser");
    }

    /**
     * 新增拼团订单人员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存拼团订单人员
     */
    @RequiresPermissions("system:orderteamuser:add")
    @Log(title = "拼团订单人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderTeamUser orderTeamUser)
    {
        return toAjax(orderTeamUserService.insertOrderTeamUser(orderTeamUser));
    }

    /**
     * 修改拼团订单人员
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OrderTeamUser orderTeamUser = orderTeamUserService.selectOrderTeamUserById(id);
        mmap.put("orderTeamUser", orderTeamUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存拼团订单人员
     */
    @RequiresPermissions("system:orderteamuser:edit")
    @Log(title = "拼团订单人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderTeamUser orderTeamUser)
    {
        return toAjax(orderTeamUserService.updateOrderTeamUser(orderTeamUser));
    }

    /**
     * 删除拼团订单人员
     */
    @RequiresPermissions("system:orderteamuser:remove")
    @Log(title = "拼团订单人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderTeamUserService.deleteOrderTeamUserByIds(ids));
    }
}
